package com.wpg.demo.spring.xml.addressbook.service.impl;

import com.wpg.demo.spring.xml.addressbook.domain.AddressBook;
import com.wpg.demo.spring.xml.addressbook.repository.AddressBookRepository;
import com.wpg.demo.spring.xml.addressbook.service.AddressBookService;
import com.wpg.demo.spring.xml.aop.TimeCounter;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * If the component has only one constructor,@Autowired annotation is not needed,
 * we can inject ApplicationContext now through @Autowired
 * @author ChangWei Li
 * @version 2017-02-20 09:54
 */
@Service
public class AddressBookServiceImpl implements AddressBookService {

    private final AddressBookRepository repository;

    public AddressBookServiceImpl(AddressBookRepository repository) {
        this.repository = repository;
    }

    @TimeCounter
    @Override
    public int add(AddressBook addressBook) {
        return repository.add(addressBook);
    }

    @TimeCounter
    @Override
    public List<AddressBook> getList() {
        return repository.getList();
    }
}
